<template>
  <div class="sc-base-list sc-design">
    <div class="q-px-md">
      <q-card
        border-radius
        q-card--flat
        shadow
        class="my-card"
        style="margin: 0 8px; padding: 0 50px"
      >
        <q-card-section>
          <div class="row items-center q-px-md" style="width: 100%">
            <div style="width: 100%">
              <q-card-section class="col-sm-9 col-xs-8 q-px-none">
                <div
                  class="row q-gutter-y-sm q-gutter-x-md justify-end"
                  style="justify-content: space-between; width: 100%"
                >
                  <div
                    class="col-md-5 col-xs-12"
                    style="
                      width: 600px;
                      border-bottom: 1px solid #ededed;
                      padding: 0 20px;
                    "
                  >
                    <q-btn-toggle
                      style="height: 36px"
                      spread
                      unelevated
                      class="no-border-radius;"
                      dense
                      v-model="listQueryData.matterState"
                      flat
                      toggle-color="primary"
                      @click="queryData"
                      :options="[
                        { label: '全部', value: '全部' },
                        { label: '资讯', value: '商圈资讯' },
                        { label: '合作', value: '商圈合作' },
                        { label: '招聘', value: '商圈招聘' }
                      ]"
                    />
                  </div>
                  <div class="col-md-3 col-xs-12" style="max-width: 280px">
                    <q-input
                      ref="ruleName"
                      placeholder="请输入搜索内容"
                      outlined
                      v-model="listQueryData.matter"
                      dense
                      @keydown.enter="queryData"
                      square
                    >
                      <template v-slot:append>
                        <q-btn
                          style="
                            margin-right: -12px;
                            width: 40px;
                            height: 100%;
                            background-color: #1890ff;
                          "
                          class="no-border-radius"
                          text-color="white"
                          dense
                          padding="xs"
                          flat
                          color="lightgrey"
                          icon="search"
                          @click="queryData"
                        ></q-btn>
                      </template>
                    </q-input>
                  </div>
                  <div class="col-md-auto col-xs-12 q-pb-sm col-sm gt-sm">
                    <q-btn
                      :ripple="false"
                      dense
                      flat
                      style="background: #1890ff; color: white; padding: 0 15px"
                      unelevated
                      icon="add"
                      class="no-border-radius q-px-sm"
                      label="添加文章"
                      @click="addTaskDialog"
                    />
                  </div>
                </div>
              </q-card-section>
            </div>
            <div class="q-mt-none q-pb-md q-px-md lt-md">
              <q-btn
                :ripple="false"
                padding="xs"
                flat
                style="border: 1px darkgrey dashed; height: 36px"
                unelevated
                icon="add"
                class="full-width no-border-radius"
                label="添加"
                @click="addTaskDialog"
              />
            </div>
          </div>
          <q-item-label
            class="text-body1 col-sm-3 col-xs-4"
            style="font-size: 16px; font-weight: bold; padding: 0 0 20px 0"
          >
            资讯列表
          </q-item-label>
        </q-card-section>
      </q-card>
      <div class="q-mt-md q-pb-md q-pt-md">
        <!-- <q-item-section v-if="filterListData.length == 0">
          <q-item-label class="text-center">
            <q-img
              src="http://wxapp.inheart.cn/img/null.png"
              class="none_img"
            ></q-img>
            <q-item-label class="q-mt-md text-grey-8">暂无数据</q-item-label>
          </q-item-label>
        </q-item-section> -->
        <sc-page
          :items="filterListData"
          :datacounts="total"
          :perNumber="pageSize"
          @ChangeCurrentPage="getChangeCurrentPage"
          @ChangeInputPagePage="getChangeInputPagePage"
          item-class="col-xl-3 col-lg-3 col-md-4 col-sm-6 col-xs-12"
        >
          <template v-slot:item="props">
            <div class="q-pb-sm">
              <sc-shadow>
                <q-card class="my-card">
                  <q-card-section>
                    <q-item-section>
                      <q-item-label
                        class="text-body1 q-mb-sm q-pl-xs"
                        style="padding-top: 20px"
                        @click="editItem(props.item)"
                      >
                        <strong class="title line">
                          {{ props.item.title }}
                        </strong>
                      </q-item-label>
                      <q-item-label
                        class="row text-body2 text-grey-7 items-center q-gutter-x-xs q-pl-xs q-pt-lg"
                        style="height: 140px"
                      >
                        <q-img
                          :src="props.item.inforimg.split(',')[0]"
                          :ratio="4 / 3"
                          v-if="props.item.inforimg.split(',')[0] != ''"
                        />
                        <q-img
                          :src="props.item.logoimg"
                          :ratio="4 / 3"
                          v-else
                        />
                        <div class="texts">
                          <div
                            class="col-auto col-xs-12"
                            style="margin-bottom: 10px"
                          >
                            发布人：{{ props.item.author }}
                          </div>
                          <div class="col-sm-auto col-xs-12">
                            {{ props.item.releasedate }}
                          </div>
                        </div>
                      </q-item-label>
                      <q-item-label
                        class="row text-body2 text-grey-7 items-center q-gutter-x-xs q-pl-xs q-pt-xs"
                      >
                      </q-item-label>
                      <q-separator />
                      <div
                        class="q-mt-md q-mb-md items-center"
                        style="
                          height: 24px;
                          display: flex;
                          justify-content: space-between;
                          align-items: center;
                          padding-top: 10px;
                        "
                      >
                        <q-btn-group flat class="float-left">
                          <q-btn
                            flat
                            dense
                            icon="star"
                            size="sm"
                            color="grey-6"
                            class="q-mr-md"
                            :label="props.item.collect | numeral('0,0')"
                          >
                            <q-tooltip>收藏数</q-tooltip>
                          </q-btn>
                          <q-separator vertical inset="" />
                          <q-btn
                            flat
                            dense
                            icon="favorite"
                            color="grey-6"
                            size="sm"
                            class="q-mr-md"
                            :label="props.item.likes | numeral('0,0')"
                          >
                            <q-tooltip>点赞数</q-tooltip>
                          </q-btn>
                          <q-separator vertical inset="" />
                          <q-btn
                            flat
                            dense
                            icon="preview"
                            size="sm"
                            color="grey-6"
                            class="q-mr-md"
                            :label="props.item.reading | numeral('0,0')"
                          >
                            <q-tooltip>阅读数</q-tooltip>
                          </q-btn>
                        </q-btn-group>
                        <q-btn-group flat class="float-right">
                        <!-- <q-btn
                        flat
                        dense
                        icon="edit"
                        size="md"
                        color="grey-6"
                        class="q-mr-md"
                        @click="editItem(props.item)"
                      >
                        <q-tooltip>编辑</q-tooltip>
                      </q-btn> 
                      <q-separator vertical inset="" />-->
                          <q-btn
                            flat
                            dense
                            icon="delete_forever"
                            size="md"
                            color="red"
                            class="q-mx-md"
                            @click="deleteItem(props.item)"
                          >
                            <q-tooltip>删除</q-tooltip>
                          </q-btn>
                          <q-separator vertical inset="" />
                          <q-btn
                            flat
                            dense
                            icon="share"
                            size="md"
                            color="grey-6"
                            class="q-mx-md"
                            @click="
                              getqrcode(props.item.infortype, props.item.id)
                            "
                          >
                            <q-tooltip>分享</q-tooltip>
                          </q-btn>
                        </q-btn-group>
                      </div>
                    </q-item-section>
                  </q-card-section>
                </q-card>
              </sc-shadow>
            </div>
          </template>
        </sc-page>
      </div>
      <q-dialog
        v-model="addTask"
        fullscreen
        @escape-key="diahide"
        @hide="diahide"
        no-backdrop-dismiss
      >
        <q-card style="width: 60%; max-width: inherit" square class="q-pb-md">
          <q-card-section
            class="row items-center"
            style="background-color: #1890ff; color: #fff; padding-left: 40px"
          >
            <div class="text-h6">{{ task_title }}</div>
            <q-space />
            <q-btn icon="close" flat round dense v-close-popup />
          </q-card-section>
          <form
            ref="addDataForm"
            @submit.prevent.stop="onSubmit"
            @reset.prevent.stop="onReset"
          >
            <q-card-section class="row justify-center">
              <div class="col-sm-12 col-xs-12 q-gutter-md">
                <q-input
                  class="q-pb-none"
                  ref="title"
                  placeholder="请输入标题"
                  outlined
                  v-model="waitEdit.title"
                  dense
                  square
                  clearable
                  :rules="[
                    (val) =>
                      (val && val.length > 3) || '请输入标题并大于3个字符'
                  ]"
                >
                  <template v-slot:before>
                    <div class="text_name">标题</div>
                  </template>
                </q-input>
                <q-toggle
                  v-model="isdatatype"
                  size="lg"
                  :icon="isdataicon"
                  @input="changedata"
                  label="选择发布文章/视频"
                  v-show="task_title == '添加'"
                />
                <q-input
                  class="q-pb-none"
                  placeholder="请输入文章链接"
                  outlined
                  v-model="waitEdit.dataurl"
                  dense
                  square
                  clearable
                  v-if="!isdatatype"
                >
                  <template v-slot:before>
                    <div class="text_name">文章链接</div>
                  </template>
                </q-input>
                <q-input
                  class="q-pb-none"
                  placeholder="请输入视频链接"
                  outlined
                  v-model="waitEdit.videourl"
                  dense
                  square
                  clearable
                  v-else
                >
                  <template v-slot:before>
                    <div class="text_name">视频链接</div>
                  </template>
                </q-input>
                <q-select
                  class="q-pb-none q-pt-sm"
                  outlined
                  v-model="waitEdit.infortype"
                  :options="options"
                  placeholder="请选择"
                  ref="infortype"
                  dense
                  square
                  clearable
                  style="margin-bottom: 22px"
                  :rules="[
                    (val) => (val && val.length > 0) || '请选择资讯类型'
                  ]"
                >
                  <template v-slot:before>
                    <div class="text_name">资讯类型</div>
                  </template>
                </q-select>
                <div class="col-12 row q-mb-md">资讯内容</div>
                <input
                  type="file"
                  style="display: none"
                  class="editorFile"
                  accept="image/*"
                  @change="handleFile_editor"
                />
                <q-editor
                  v-model="qeditor"
                  :dense="$q.screen.lt.md"
                  :definitions="{
                    upload: {
                      tip: '上传图片',
                      icon: 'cloud_upload',
                      label: '上传',
                      handler: uploadIt
                    }
                  }"
                  :toolbar="[
                    [
                      {
                        label: '排列',
                        icon: $q.iconSet.editor.align,
                        fixedLabel: true,
                        list: 'only-icons',
                        options: ['left', 'center', 'right', 'justify']
                      }
                    ],

                    [
                      'bold',
                      'italic',
                      'strike',
                      'underline',
                      'subscript',
                      'superscript'
                    ],
                    ['token', 'hr', 'link', 'custom_btn'],
                    ['print', 'fullscreen'],
                    [
                      {
                        label: $q.lang.editor.formatting,
                        icon: $q.iconSet.editor.formatting,
                        list: 'no-icons',
                        options: [
                          'p',
                          'h1',
                          'h2',
                          'h3',
                          'h4',
                          'h5',
                          'h6',
                          'code'
                        ]
                      },
                      {
                        label: ' 字体大小',
                        icon: $q.iconSet.editor.fontSize,
                        fixedLabel: true,
                        fixedIcon: true,
                        list: 'no-icons',
                        options: [
                          'size-1',
                          'size-2',
                          'size-3',
                          'size-4',
                          'size-5',
                          'size-6',
                          'size-7'
                        ]
                      },
                      {
                        label: '默认字体',
                        icon: $q.iconSet.editor.font,
                        fixedIcon: true,
                        list: 'no-icons',
                        options: [
                          'default_font',
                          'arial',
                          'arial_black',
                          'comic_sans',
                          'courier_new',
                          'impact',
                          'lucida_grande',
                          'times_new_roman',
                          'verdana'
                        ]
                      },
                      'removeFormat'
                    ],
                    ['quote', 'unordered', 'ordered', 'outdent', 'indent'],
                    ['upload'],
                    ['undo', 'redo'],
                    ['viewsource']
                  ]"
                  :fonts="{
                    arial: 'Arial',
                    arial_black: 'Arial Black',
                    comic_sans: 'Comic Sans MS',
                    courier_new: 'Courier New',
                    impact: 'Impact',
                    lucida_grande: 'Lucida Grande',
                    times_new_roman: 'Times New Roman',
                    verdana: 'Verdana'
                  }"
                  style="min-height: 26rem"
                />
                <div class="col-12 row q-mb-md">资讯封面图</div>
                <div class="col-12 row flexRow">
                  <el-upload
                    class="upload-demo"
                    :action="
                      upload_url +
                      '?guestcode=' +
                      waitEdit.guestcode +
                      '&imgpjid=' +
                      waitEdit.pjid
                    "
                    :on-preview="handlePreview"
                    :on-remove="handleRemove"
                    :file-list="fileList"
                    list-type="picture-card"
                    :limit="9"
                  >
                    <i class="el-icon-plus"></i>
                  </el-upload>
                  <el-dialog :visible.sync="dialogVisible">
                    <img w-full :src="dialogImageUrl" alt="Preview Image" />
                  </el-dialog>
                </div>

                <div class="text-right">
                  <q-btn
                    outline
                    unelevated
                    label="取消"
                    v-close-popup
                    type="reset"
                    class="q-mr-sm no-border-radius"
                    color="grey-6"
                  />
                  <q-btn
                    unelevated
                    type="submit"
                    label="发布"
                    color="primary"
                    class="no-border-radius"
                    v-if="isEdit == '0'"
                    :loading="loginLoading"
                  />
                  <q-btn
                    unelevated
                    type="submit"
                    label="保存"
                    color="primary"
                    class="no-border-radius"
                    :loading="loginLoading"
                    v-else
                  />
                </div>
              </div>
            </q-card-section>
          </form>
        </q-card>
      </q-dialog>
    </div>
  </div>
</template>
<script>
import ScShadow from 'components/shadow/ScShadow'
import ScPage from 'components/common/ScPage'
import BASIC_LIST_DATA from '@/mock/data/list/basicListData'
import _ from 'lodash'
import commonUtil from 'src/utils/commonUtil'
import { getLoginData } from '@/utils/localStorage'
import { baseUrl, imgUrl, proUrl } from '@/utils/config'
import {
  GetDefaultlistApi,
  ReleasedataApi,
  Op_inforApi,
  RemoveInews,
  delimgApi,
  AdduploadImgS,
  uploadImg
} from '@/api/cardApi'

export default {
  name: 'comInfor',
  data() {
    return {
      infortype: '全部',
      basicListData: BASIC_LIST_DATA,
      listQueryData: {
        matterState: '全部',
        matter: ''
      },
      addTask: false,
      filterListData: [],
      waitEdit: {},
      page: 1,
      pageSize: 12,
      total: 0,
      qeditor: '',
      se_kindtype: null,
      options: ['商圈资讯', '商圈合作', '商圈招聘'],
      isEdit: '',
      loginLoading: false,
      httpimgUrl: 'http://img.inheart.cn',
      userInfo: {},
      task_title: '添加',
      imgfileList: [],
      upload_url: proUrl + '/api/InheartApi/uploadimg',
      keyword: '',
      pjid: '',
      dialogVisible: false,
      dialogImageUrl: '',
      advfileList: [],
      isdatatype: false,
      isdataicon: 'article',
      fileList: [],
      msg: '上传'
    }
  },
  computed: {},
  methods: {
    getChangeCurrentPage(val) {
      this.GetDefaultlist(val, '', '')
    },
    getChangeInputPagePage(val) {
      this.GetDefaultlist(val, '', '')
    },
    //

    //查询
    GetDefaultlist(pageindex) {
      let that = this
      let guestcode = that.userInfo.reguserno
      let gscode = that.userInfo.gscode
      let rkeyword = that.keyword
      GetDefaultlistApi({
        guestcode: guestcode,
        gscode: gscode,
        pagesize: that.pageSize,
        pageindex: pageindex,
        keyword: rkeyword,
        stype: that.infortype
      }).then((res) => {
        //console.log(res.data)
        if (res.code == 0 && res.data.length > 0) {
          res.data.forEach((element) => {
            element.mdimg =
              imgUrl + element.mdimg.split(',')[0].replace(imgUrl, '')
            if (
              element.logoimg != '' &&
              element.logoimg !=
                'http://www.iqp168.com/src/assets/img/logo240x240.jpg'
            ) {
              element.logoimg = imgUrl + element.logoimg.replace(imgUrl, '')
            } else {
              element.logoimg =
                'http://www.iqp168.com/src/assets/img/logo240x240.jpg'
            }
          })
          that.filterListData = res.data
          that.total = res.dataCount
        } else {
          that.filterListData = []
        }
      })
    },
    queryData() {
      let that = this
      const listQueryData = this.listQueryData
      if (listQueryData.matterState === '全部') {
        that.infortype = '全部'
      } else {
        that.infortype = listQueryData.matterState
      }
      that.keyword = listQueryData.matter
      that.GetDefaultlist(1)
    },
    isMatchData(data) {
      const listQueryData = this.listQueryData
      let matterFlag = false
      if (
        !listQueryData.matter ||
        data.matter.search(listQueryData.matter) !== -1
      ) {
        matterFlag = true
      }
      let matterStateFlag = false
      if (
        listQueryData.matterState === '全部' ||
        data.state === listQueryData.matterState
      ) {
        matterStateFlag = true
      }
      return matterFlag && matterStateFlag
    },

    //文本编辑器上传图片
    uploadIt() {
      this.EditorFileUpload()
    },
    EditorFileUpload() {
      document.getElementsByClassName('editorFile')[0].click()
    },
    AdvimgUpload() {
      document.getElementsByClassName('advFile')[0].click()
    },
    // 上传头像
    handleFile_logo: function (e) {
      const $target = e.target
      const file = $target.files[0]
      const reader = new FileReader()
      // reader.onload = (data) => {
      //   const res = data.target
      //   this.userBasicData.avatar = res.result
      // }
      reader.readAsDataURL(file)
      this.headFile = file
      const formData = new FormData()
      formData.append('file', this.headFile)
      formData.append('guestcode', this.userInfo.reguserno)
      formData.append('gscode', this.userInfo.Gscode)
      formData.append('imgtype', 'logo')

      e.target.value = ''
      uploadImg(formData).then((res) => {
        if (res.status == '200') {
          commonUtil.notifySuccess('上传成功')
          let url = res.status
          let urlImg = res.statusText
          this.appImg.logo = this.httpimgUrl + urlImg + '&original=1'
        }
      })
    },
    //上传app
    handleFile_appimg: function (e) {
      const $target = e.target
      const file = $target.files[0]
      const reader = new FileReader()
      // reader.onload = (data) => {
      //   const res = data.target
      //   this.userBasicData.avatar = res.result
      // }
      reader.readAsDataURL(file)
      this.headFile = file
      const formData = new FormData()
      formData.append('file', this.headFile)
      formData.append('guestcode', this.userInfo.reguserno)
      formData.append('gscode', this.userInfo.Gscode)
      formData.append('imgtype', 'appimg')

      e.target.value = ''
      uploadImg(formData).then((res) => {
        if (res.status == '200') {
          commonUtil.notifySuccess('上传成功')
          let url = res.status
          let urlImg = res.statusText
          this.appImg.appimg = this.httpimgUrl + urlImg + '&original=1'
        }
      })
    },
    // 文本编辑器上传图片
    handleFile_editor: function (e) {
      const $target = e.target
      const file = $target.files[0]
      const reader = new FileReader()
      reader.readAsDataURL(file)
      this.headFile = file
      const formData = new FormData()
      formData.append('file', this.headFile)
      //console.log(formData, file)
      e.target.value = ''
      uploadimg(formData).then((res) => {
        if (res.code == '0') {
          commonUtil.notifySuccess('上传成功')
          let urlImg = res.url
          let url = imgUrl + urlImg + '&original=1'
          let shtml = '<img style="max-width:100%" src="' + url + '"/>'
          this.qeditor = this.qeditor + shtml
        } else {
          commonUtil.notifyError(res)
        }
      })
    },
    onReset() {
      this.waitEdit.title = null
      this.waitEdit.name = null
      this.waitEdit.startTime = null
      this.waitEdit.desc = null
      this.waitEdit.id = null
      this.waitEdit.state = null
    },
    //添加按钮
    addTaskDialog() {
      this.fileList = []
      this.isEdit = '0'
      this.waitEdit = {}
      this.addTask = true
      this.qeditor = ''
      this.task_title = '添加'
      this.imgfileList = []
      this.getCurrentTime()
      this.waitEdit.guestcode = this.userInfo.reguserno
      this.waitEdit.pjid = this.pjid
    },
    // 点标题编辑
    editItem(item) {
      this.isEdit = '1'
      this.addTask = true
      this.waitEdit = _.clone(item)
      this.qeditor = item.body
      this.task_title = '编辑资讯'
      this.fileList = []
      this.fileList = this.waitEdit.inforimg.split(',').map((url, index) => ({
        name: `food${index + 1}.jpeg`,
        url: url
      }))
    },
    deleteimg(url) {
      let that = this
      let data_imgUrl = ''
      const index = that.fileList.indexOf(url)
      // console.log(url);
      that.$q
        .dialog({
          title: '提示',
          message: '是否确认删除?',
          cancel: {
            'text-color': 'black',
            color: 'white',
            label: '取消'
          },
          ok: {
            label: '确定'
          },
          persistent: true
        })
        .onOk(() => {
          that.imgfileList.splice(index, 1)
          that.imgfileList.forEach((element) => {
            data_imgUrl +=
              element.replace(imgUrl, '').replace('&original=1', '') + ','
          })
          delimgApi({
            guestcode: that.waitEdit.guestcode,
            imgurl: url
          }).then((res) => {
            if (res.code == '0') {
              commonUtil.notifySuccess('删除成功')
            }
          })
        })
        .onCancel(() => {})
    },
    deleteItem(item) {
      let that = this
      that.waitEdit = _.clone(item)
      const addModel = _.clone(that.waitEdit)
      addModel.guestcode = that.userInfo.reguserno
      addModel.gscode = that.userInfo.gscode
      that.$q
        .dialog({
          title: '提示',
          message: '是否确认删除?',
          cancel: {
            'text-color': 'black',
            color: 'white',
            label: '取消'
          },
          ok: {
            label: '确定'
          },
          persistent: true
        })
        .onOk(() => {
          RemoveInews(addModel).then((res) => {
            if ((res.code = '0')) {
              that.$q.notify({
                color: 'white',
                textColor: 'positive',
                icon: 'check_circle',
                position: 'top',
                message: '删除成功'
              })
              that.GetDefaultlist(1)
            }
          })
        })
        .onCancel(() => {})
    },
    diahide() {
      let that = this
      that.GetDefaultlist(1)
    },
    onSubmit() {
      let that = this
      that.loginLoading = true
      let addModel = {}
      if (!that.$refs.title.validate()) {
        that.loginLoading = false
        return
      }
      if (!that.$refs.infortype.validate()) {
        that.loginLoading = false
        return
      }
      if (that.isEdit == '0') {
        addModel.guestcode = that.userInfo.reguserno
        addModel.gscode = that.userInfo.gscode
        addModel.imgpjid = that.pjid
        addModel.title = that.waitEdit.title
        addModel.body = that.qeditor
        addModel.infortype = that.waitEdit.infortype
        addModel.author = that.userInfo.userName
        addModel.dataurl = that.dataurl ?? ''
        addModel.videourl = that.videourl ?? ''
        ReleasedataApi(addModel).then((res) => {
          if (res.code == '0') {
            that.$q.notify({
              color: 'white',
              textColor: 'positive',
              icon: 'check_circle',
              position: 'top',
              message: '发布成功'
            })
            setTimeout(() => {
              that.GetDefaultlist(1)
              that.loginLoading = false
              that.addTask = false
            }, 1000)
          } else {
            that.$q.notify({
              color: 'white',
              textColor: 'positive',
              icon: 'check_circle',
              position: 'top',
              message: res.msg
            })
            that.loginLoading = false
          }
        })
      } else {
        addModel = _.clone(that.waitEdit)
        //资讯信息
        addModel.title = that.waitEdit.title
        addModel.body = that.qeditor
        addModel.infortype = that.waitEdit.infortype
        addModel.dataurl = that.dataurl ?? ''
        addModel.videourl = that.videourl ?? ''
        //日志信息
        addModel.op_type = 'edit'
        addModel.username = that.userInfo.userName
        addModel.headimg = that.userInfo.headerImg
        addModel.openid = that.userInfo.openid ?? ''
        addModel.id = that.waitEdit.id
        Op_inforApi(addModel).then((res) => {
          if (res.code == '0') {
            that.$q.notify({
              color: 'white',
              textColor: 'positive',
              icon: 'check_circle',
              position: 'top',
              message: '修改成功'
            })
            setTimeout(() => {
              that.loginLoading = false
              that.addTask = false
              that.GetDefaultlist(1)
            }, 1000)
          } else {
            that.$q.notify({
              color: 'white',
              textColor: 'positive',
              icon: 'check_circle',
              position: 'top',
              message: res.msg
            })
            that.loginLoading = false
          }
        })
      }
    },
    getqrcode(val, inforid) {
      let that = this
      let optype = ''
      let guestcode = that.userInfo.reguserno
      let id = inforid
      that.isqrcode = true
      if (val == '商圈资讯' || val == '商圈合作' || val == '商圈招聘') {
        optype = 'infor'
      }
      getwxacodeunlimitApi({
        id: id,
        guestcode: guestcode,
        op_type: optype
      }).then((res) => {})
    },
    changedata() {
      let that = this
      if (that.isdatatype) {
        that.isdataicon = 'video_library'
      } else {
        that.isdataicon = 'article'
      }
    },
    //上传
    handleRemove(file, fileList) {
      console.log(file, fileList)
      let that = this
      let data_imgUrl = ''
      let url
      if (file.response) {
        url = file.response.url + file.response.data
      } else {
        url = file.url
      }
      if (url.substring(0, 5) == 'blob:') {
        return
      }
      const index = this.fileList.findIndex((item) => item.url === url)
      if (index !== -1) {
        this.fileList.splice(index, 1)
      }
      delimgApi({
        guestcode: that.waitEdit.guestcode,
        imgurl: url
      }).then((res) => {
        if (res.code == '0') {
          commonUtil.notifySuccess('删除成功')
        }
      })
    },
    handlePreview(file) {
      this.dialogImageUrl = file.url
      this.dialogVisible = true
    },
    handleFile_advimg: function (e) {
      const $target = e.target
      const file = $target.files[0]
      const reader = new FileReader()
      reader.readAsDataURL(file)
      this.headFile = file
      const formData = new FormData()
      const Data = new FormData()
      formData.append('file', this.headFile)
      Data.append('img', file)
      formData.append('guestcode', this.userInfo.reguserno)
      formData.append('gscode', this.userInfo.Gscode)
      formData.append('imgtype', 'advimg')
      e.target.value = ''
      AdduploadImgS(this.waitEdit.guestcode, this.waitEdit.pjid, Data).then(
        (res) => {
          if (res.status == '200') {
            commonUtil.notifySuccess('上传成功')
            let url = res.url
            let urlImg = res.data
            // this.advfileList.push(url + urlImg)
          }
        }
      )
    },
    delete_advimg(url) {
      let advUrl = ''
      var index = this.advfileList.indexOf(url)
      this.advfileList.splice(index, 1)
      let guestcode = this.userInfo.reguserno
      let gscode = this.userInfo.Gscode
      this.advfileList.forEach((element) => {
        advUrl +=
          element.replace(this.httpimgUrl, '').replace('&original=1', '') + ','
      })
      deladvimgApi({
        guestcode: guestcode,
        gscode: gscode,
        advimg: advUrl.slice(0, advUrl.length - 1)
      }).then((res) => {
        if (res.code == '0') {
          commonUtil.notifySuccess(res.msg)
        }
      })
    },
    getCurrentTime() {
      let yy = new Date().getFullYear()
      let mm = new Date().getMonth() + 1
      let dd = new Date().getDate()
      let hh = new Date().getHours()
      let mf =
        new Date().getMinutes() < 10
          ? '0' + new Date().getMinutes()
          : new Date().getMinutes()
      let ss =
        new Date().getSeconds() < 10
          ? '0' + new Date().getSeconds()
          : new Date().getSeconds()
      var code = ''
      var codeLength = 6
      var random = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
      for (var i = 0; i < codeLength; i++) {
        var index = Math.floor(Math.random() * 9)
        code += random[index]
      }
      this.pjid = yy + mm + dd + hh + mf + ss + code
    }
  },
  components: {
    ScPage,
    ScShadow
  },
  mounted() {
    const user = getLoginData()
    if (user == null) {
      this.$router.push('/user/login')
      return
    }
    this.userInfo = user
    this.GetDefaultlist(1, '', '')
  },
  watch: {
    // basicListData: {
    //   handler(newName, oldName) {
    //     console.log(newName, oldName)
    //     this.queryData()
    //   },
    //   immediate: true,
    //   deep: true
    // }
  }
}
</script>

<style scoped>
.q-editor__content {
  max-height: 26rem;
}
.title-more {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  /*截取2行*/
  -webkit-box-orient: vertical;
}
.text-more {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  /*截取2行*/
  -webkit-box-orient: vertical;
  padding: 0 16px;
  font-size: 12px;
}
.q-img {
  max-width: 150px;
}
.none_img {
  max-width: 300px;
  width: 300px;
}

.q-pt-md {
  padding-top: 5px !important;
}
.q-pt-lg {
  padding-top: 0;
}
.el-upload__tip {
  font-size: 12px;
  color: #ff0000;
  display: block;
  padding: 10px;
}

.title {
  color: #333;
  font-size: 16px;
  margin: 0;
}
#OldButton {
  display: none;
}
.texts {
  font-size: 14px;
  padding-left: 10px;
}
::v-deep .q-gutter-md {
  width: 100% !important;
}
.text_name {
  width: 60px;
  text-align: left;
  color: #000;
  font-size: 14px;
}
q-input {
  border-radius: 5px;
}
.line {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}
:deep(.el-upload-list) {
  display: flex;
  width: 100%;
}
:deep(.el-upload-list__item-name) {
  display: none !important;
}
:deep(.el-upload-list--picture .el-upload-list__item-thumbnail) {
  width: 250px;
  height: 180px;
}
:deep(.el-upload-list--picture .el-upload-list__item) {
  margin-right: 10px;
  height: 200px;
  padding-right: 22px;
}
#NewButton {
  width: 200px;
}
.flexRow {
  display: flex;
}
:deep(.el-upload-list--picture .el-upload-list__item) {
  width: auto;
}
:deep(.el-upload-list) {
  display: flex;
  flex-wrap: wrap;
}
</style>
